// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var dialog = require("dialog");
	var _css = require("./pledgeEvaluationSheet.css");
	var router = require("../hash/pageRouter");
	var tools = require("tools");
	var databind = require("databind");
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var init = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
		
		base.alert(2, "请先输入客户名称，再执行搜索");

		initEvent();
	};
	var initEvent = function() {
		$("#pledgeEvaluationSheet .blue_search_btn").unbind("click").click(function(){
			inquireNormalPickupApplicationList();
		});
		
		$("#pledgeEvaluationSheet .export").unbind("click").click(function(){
			exportCapitalExcel();
		});
	};
	
	var inquireNormalPickupApplicationList = function() {
		//搜索条件初始化
		var oData = {
			enterpriseName: $("#pledgeEvaluationSheet input[name=enterpriseName]").val(),
			dateEnd: $("#pledgeEvaluationSheet input[name=dateEnd]").val(),
			dateBegin: $("#pledgeEvaluationSheet input[name=dateBegin]").val(),
			pageIndex: pageIndex,
			pageSize: pageSize
		};
		tools.loadList("inquireNormalPickupApplicationList.json", $("#pledgeEvaluationSheet .pledgeTable"), $("#pledgeEvaluationSheet script"), oData, function(){
			initClickEvent();
		});
	};
	
	var initClickEvent = function(){
		$.each($("#pledgeEvaluationSheet .valuationSum"), function() {
			var sum = 0;
			var $this = $(this);
			$.each($this.parent().find("div"), function() {
				var $_this = $(this);
				if ($_this.attr("class") != "valuationSum") {
					sum = sum*1 + $_this.html()*1;
				}
			});
			$(this).html("总额:" + sum.toFixed(2));
		});
	};
	
	return {
		init: init
	};
});